<template>
    <div>
住户信息修改
    </div>
    <updatelist></updatelist>
    <el-table :data="filterTableData.slice((currentPage4-1)*pageSize4,currentPage4*pageSize4)" height="250" style="width: 100%">
      <el-table-column prop="date" label="Date"  />
      <el-table-column prop="name" label="Name"  />
      <el-table-column prop="address" label="Address" />

      <!-- 搜索输入框 -->
      <el-table-column align="right">
      <template #header>
        <el-input v-model="search" size="small" placeholder="Type to search" />
      </template>
     </el-table-column>
     <!-- 添加和修改按钮 -->
     <el-table-column>
        <template #default="scope">
            <el-button size="small" @click="handleEdit(scope.$index, scope.row)"
            >修改</el-button
            >
            <el-button
            size="small"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
            >
        </template>
    </el-table-column>
    </el-table>
    
    <!-- 分页器 -->
    <el-pagination layout="total, sizes, prev, pager, next, jumper" :total="store.state.homeview.tableData.length"  @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage4"/>
</template>

<script lang="ts" setup>
import {ref, computed} from 'vue'
import updatelist from '../components/UpdateDialog.vue'
// 引入store
import {useStore} from 'vuex'
// 得到store对象
const store=useStore()
const currentPage4 = ref(1)//当前页数
const pageSize4 = ref(100)//每页显示条数
const search=ref('')//搜索内容
// 计算属性过滤数据--搜素框有内容时只显示包含搜索的内容
const filterTableData=computed(()=>
store.state.homeview.tableData.filter((data)=>
        // 有搜素值时进行后面计算；没有搜素值时不进行后面计算，保持之前的数据
        !search.value||data.name.toLocaleLowerCase().includes(search.value.toLocaleLowerCase())
        ////////////////////
    )
)
// 删除修改按钮接口
interface User {
    date: string
    name: string
    address: string
    }
// 删除修改按钮方法
const handleEdit = (index: number, row: User) => {
console.log(index, row)
// 调用vuex中mutation修改
store.commit('SET_DIALOG')
console.log(store.state.homeview.dialogFormVisible);

}
const handleDelete = (index: number, row: User) => {
console.log(index, row)
}
const handleSizeChange = (val: number) => {//一页显示多少条内容
    pageSize4.value=val
}
const handleCurrentChange = (val: number) => {//修改当前页面
    currentPage4.value=val
}
</script>